var prefix = ctx + "business/weeklyInfo"

function initTable(weeklytype){
	var columns = [{
        checkbox: true
    },
	{
		field : 'weeklyName', 
		title : '周刊名称' 
	},
	{
		field : 'articleType', 
		title : '类别' 
	},
	{
		field : 'imageUrl', 
		title : '头图图片'	,
		formatter: function(value, row , index){
			return '<img src="'+value+'" width="150px" height="80px">'; 
		}
	},
	{
		field : 'source', 
		title : '来源' 
	},
	{
		field : 'status', 
		title : '状态' ,
		formatter: function(value, row, index) {
            if (value == '0') {
                return '<span class="badge badge-primary">显示</span>';
            } else if (value == '1') {
                return '<span class="badge badge-danger">不显示</span>';
            }
        }
	},
	{
		field : 'orderBy', 
		title : '排序' 
	},
	{
		field : 'createBy', 
		title : '创建人' 
	},
	{
		field : 'createTime', 
		title : '创建时间' 
	},
    {
        title: '操作',
        align: 'center',
        formatter: function(value, row, index) {
        	var actions = [];
			actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\', \'' + weeklytype + '\')"><i class="fa fa-edit">编辑</i></a> ');
			actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove">删除</i></a>');
			return actions.join('');
        }
    }];
	var url = prefix + "/list?weeklyType="+weeklytype+"";
	$.initTable(columns, url);
}


/*M5周刊-新增*/
function add(weeklytype) {
    var url = prefix + '/add?weeklyType='+weeklytype+'';
    layer_show("新增M5周刊", url, '1100', '');
}

/*M5周刊-修改*/
function edit(id, weeklytype) {
    var url = prefix + '/edit/' + id+'?weeklyType='+weeklytype+'';
    layer_show("修改M5周刊", url, '1100', '');
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中M5周刊吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("id");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
